<?php
//产品中心页面
$curr_page =1;
include 'head.php';

if(isset($_GET['type']))
{
	$type = $_GET['type'];
}else
{
	$type =false;
}

$current_page = 1;//当前第几页
$pages = 9;//每页几条
$Count =0;//总共多少条

//检查当前页是否合法
if(isset($_GET['pages']))
{
	$current_page = $_GET['pages']+1;
}

    if($type)
  {
    $sql =  "select count(*) as num from en_product where flag = 1 and find_in_set('{$type}', type_id)";
  }
  else
  {
    $sql =  "select count(*) as num from en_product where flag = 1";
  }
//查询总条数
  
  $row = mysql_fetch_array(mysql_query($sql));
  $Count = $row["num"];


  
?>
<link href="1.css" rel="stylesheet" type="text/css">
<link href="js/pagination/pagination.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="js/jquery-1.7.1.js"></script>
<script type="text/javascript" src="js/pagination/jquery.pagination.js"></script>
<style>
 .nava{
 	color:#369;
	text-decoration:none;
 }
 .nava:hover{
	text-decoration:underline;
 }
</style>
<script>
	$(document).ready(function(){
			
			$("#Pagination").pagination(<?php echo $Count;?>, {
			    num_edge_entries: 1,//边缘页数
			    num_display_entries: 4,//主体页数
			    current_page:<?php echo $current_page-1;?> ,
			    items_per_page:<?php echo $pages;?>,//每页显示项
			    link_to:"?type=<?php echo $type;?>&pages=__id__",
			    callback:function(){}
			});
		});
</script>

     <div id="main" style="margin:0 auto;background: #FFFFFF; width:960px; height:1047px;">
	     
		 <div id="dh" style="background:none;">
		
			 
			 <div class="gg1" style=" width:175px; height:226px;background-image: url(images/xw_lbbj_2.png);">
			 
			 		<div class="gddh">Products</div>
			 		<?php
			 			$sql = "select id,name from en_pro_type where flag =1"; 
			 			$result = mysql_query($sql);
			 			while($row = mysql_fetch_array($result))
			 			{
			 		?>
			 			<div class="gddh1"><a class="nava" href="?type=<?php echo $row['id'];?>" ><?php echo $row['name'];?></a></div>
			 		<?php
			 			}
			 		?>
					
					
				
			 </div>
			 <div class="nrdh"><h1 style="text-indent:16px; margin-top:11px;">Products</h1></div>
			 
			 <div style="width:735px; height:979px; border:1px solid #c8c8c8; float:right; margin-right:16px; margin-top:-1px;">
			 
			 	<div style="width:717px; height:920px;margin:0 0 0 9px; ">
			 		<?php
			 		if($type)
                    {
                        $sql = "select a.id,a.name,a.model,a.tao_link,a.type_id,a.price,a.path,a.remark,a.content,a.dates,a.ishot,a.isnews from en_product as a 
                        where a.flag =1 and find_in_set('{$type}', a.type_id) limit ".($current_page-1)*$pages.",".$pages;
                    }
                    else
                    {
                        $sql = "select a.id,a.name,a.model,a.tao_link,a.type_id,a.price,a.path,a.remark,a.content,a.dates,a.ishot,a.isnews from en_product as a 
                        where a.flag =1  limit ".($current_page-1)*$pages.",".$pages;
                    }

                        $result = mysql_query($sql);
                        $i = 0;
                        while($row = mysql_fetch_array($result))
                        {
                            $sql_t1 = "select * from en_pro_type where id in ({$row['type_id']})";
                            $ret_t1 = mysql_query($sql_t1);
                            while ($row_t1 = mysql_fetch_array($ret_t1))
                            {
                                $row['type_name'] .= $row_t1['name']." ";
                            }
                            
                            if(cnStrLen($row['type_name']) > 10)
                              $row['type_name'] = cnSubStr($row['type_name'],0,9)."...";
                              
                            $sql_t2 = "select count(*) from en_download where pro_id = {$row['id']}";
                            $ret_t2 = mysql_query($sql_t2);
                            $rcd_t2 = mysql_fetch_array($ret_t2);
                            
                            if($rcd_t2[0] > 0)
                              $row['has_download'] = true;
                            else
                              $row['has_download'] = false;
                              
                            if($i%3==0)
                            {
			 		?>
									 		  
			 			<div class="product" style="float:left;margin-top:12px;">
							<div style=" width:204px; height:147px; margin:12px 0 0 11px;">
								<a href="product_info.php?id=<?php echo $row['id'];?>"><img src="<?php echo $row['path'];?>" style="width:204px; height:147px;" /></a>
							</div>
						    <div class="wz">
								<div  style="color:#81a615;">Item：<span style=" font-weight:normal;"><?php echo $row['name'];?></span></div>
								<div style="margin-top:5px;">Model：<span style=" font-weight:normal;"><?php echo $row['model'];?></span></div>
								<?php if($row['has_download']){?>
								<div style="margin-top:5px;">Download：<span style=" font-weight:normal;"><a href="download1.php?id=<?php echo $row['id'];?>">Click</a></span></div>
								<?php }?>
								<div style="margin-top:5px;">Ebay：<span style=" font-weight:normal;"><a href="d<?php echo $row['tao_link'];?>"><img src="images/buytb.png" style="vertical-align: middle;" /></a></span></div>
								<div style="margin-top:5px;">Type：<span style=" font-weight: bold; color:#336699"><?php echo $row['type_name'];?></span></div>
								<div style="margin-top:5px;">Price：<span style=" font-weight:normal; color:#f08200">$<?php echo $row['price'];?></span></div>
								<div style="margin-top:5px;">Summary：<span style=" font-weight:normal;"><?php echo $row['remark'];?></span></div>
							</div>
							
						</div>	
			 		<?php
			 				}else {
			 		?>
			 			<div class="product" style="float:left; margin-left:15px;margin-top:12px; ">
							<div style=" width:204px; height:147px; margin:12px 0 0 11px;">
								<a href="product_info.php?id=<?php echo $row['id'];?>"><img src="<?php echo $row['path'];?>" style="width:204px; height:147px;" /></a>
							</div>
						    <div class="wz">
								<div  style="color:#81a615;">Item：<span style=" font-weight:normal;"><?php echo $row['name'];?></span></div>
								<div style="margin-top:5px;">Model：<span style=" font-weight:normal;"><?php echo $row['model'];?></span></div>
								<?php if($row['has_download']){?>
								<div style="margin-top:5px;">Download：<span style=" font-weight:normal;"><a href="download1.php?id=<?php echo $row['id'];?>">Click</a></span></div>
								<?php }?>
								<div style="margin-top:5px;">Ebay：<span style=" font-weight:normal;"><a href="d<?php echo $row['tao_link'];?>"><img src="images/buytb.png" style="vertical-align: middle;" /></a></span></div>
								<div style="margin-top:5px;">Type：<span style=" font-weight: bold; color:#336699"><?php echo $row['type_name'];?></span></div>
								<div style="margin-top:5px;">Price：<span style=" font-weight:normal; color:#f08200">$<?php echo $row['price'];?></span></div>
								<div style="margin-top:5px;">Summary：<span style=" font-weight:normal;"><?php echo $row['remark'];?></span></div>
							</div>
							
						</div>
			 		<?php
			 				}
			 			$i ++;
			 			}
			 		?>
				
					
					 </div>	
						
						<div id="Pagination" class="pagination" style=" float:left; text-align:center; width:717px; height:28px; margin-top:13px;">
						
						</div>
						
					
			 
						
				
		
			

			</div>
			
			 <div class="gg2" style="margin-top:15px; margin-left:16px; background:none;">
			 <?php
			   $sql = "select * from en_ad where id = 1";
			   $ret = mysql_query($sql);
			   $rcd = mysql_fetch_array($ret);
			 ?>
			 <a href="<?php echo $rcd['link']?>" target='_blank'><img src="<?php echo $rcd['pic_path'];?>" /></a>
			 </div>
			 <div class="gg2" style=" background-image:none;margin-top:15px; margin-left:16px;">
			 <?php
			   $sql = "select * from en_ad where id = 2";
			   $ret = mysql_query($sql);
			   $rcd = mysql_fetch_array($ret);
			 ?>
			 <a href="<?php echo $rcd['link']?>" target='_blank'><img src="<?php echo $rcd['pic_path'];?>" /></a>
			 </div>
			 
			 
			 
	     </div>
		  
	 </div>
	 <?php include 'bottom.php';?>

 
